#!/usr/local/bin/python3
# -*- coding: utf-8 -*-

"""
@File    : charts.py
@Author  : different
@Time    : 2021-8-5 17:49
@Desc    : echarts

"""
from flask import render_template, request

from apps.view import charts_bp
from expand import login_required
from expand.exp_data.exp_chart_data import ChartData


@charts_bp.route('/charts/<pk>')
@login_required
def charts(pk):
    if request.method == 'GET':
        chart = ChartData(pk)
        # 获取标题
        text_title = chart.text_title()
        # Rating区间销量占比
        rating_data = chart.rating_chart()
        # 价格区间销量占比
        price_data = chart.price_chart()
        # 上架时间销量占比
        add_time_data = chart.add_time_chart()
        # 评分区间销量占比
        score_data = chart.score_chart()
        # 评分星级个数占比
        rating_stars_data = chart.rating_stars()
        # Top5品牌销量占比
        top5_data = chart.top5_chart()

        data = [rating_data, price_data, add_time_data, score_data, rating_stars_data, top5_data]
        return render_template('charts.html', data=data, text_title=text_title)
    return None
